Return * for n number of times


Posted by Christy on 2022-04-19

Description: Write a function that accepts a number n and returns * for n number of times

function star(n) {

}

console.log(star(3)); // ***
function star(n) {
  let result = "";
  for (let i = 1; i <= n; i++) {
    result += "*";
  }
  return result;
}

console.log(star(3));

Be careful about the way of ouput, if it's print -> console.log; if it's return -> return










Related Posts

實物選擇權理論應用於發電項目:A Review

實物選擇權理論應用於發電項目:A Review

利用 JavaScript 實作簡易 TodoList

利用 JavaScript 實作簡易 TodoList

3.  React 語法糖:JSX

3. React 語法糖:JSX


Comments